import java.util.Stack;

@SuppressWarnings("rawtypes")
public class Evaluador {
	private Stack<Atributo> atributos;
	
	public Evaluador() {
		atributos = new Stack<Atributo>();
	}

	public <Valor> Atributo<Valor> evalua(Atributo<Valor> atributo) {
		atributos.push(atributo);
		while (!atributos.isEmpty()) {
			Atributo top = atributos.peek();
			Atributo newTop = top.siguienteDependencia();
			if (newTop == null) {
				if (Config.DEBUG) {
					System.out.print("VALOR DE " + top.descripcion());
				}
				top.calcula();
				if (Config.DEBUG) {
					System.out.println(" ===> " + top.val());
				}
				atributos.pop();
			} else {
				atributos.push(newTop);
			}
		}
		return atributo;
	}
}
